home *** CD-ROM | disk | FTP | other *** search
- /*
- File: MemHook.h
-
- Contains: MemoryHook class interface
-
- Owned by: Michael Burbidge, Jens Alfke
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <1> 9/13/96 jpa first checked in
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _MEMHOOK_
- #define _MEMHOOK_
-
- #ifndef _PLATFMEM_
- #include "PlatfMem.h"
- #endif
-
- #ifndef __STDDEF__
- //#include <stddef.h>
- #endif
-
- #ifndef __TYPES__
- //#include <Types.h>
- #endif
-
-
- //========================================================================================
- // Forward class declarations
- //========================================================================================
-
- class MemoryHookList;
-
-
- #if MM_DEBUG
- //========================================================================================
- // ODMemoryHook (MM_DEBUG only)
- //
- // A Memory hook that can be used to track heap operations by subclassing ODMemoryHook
- // and overriding the methods of interest. Your subclass is then registered with a
- // MemoryHeap.
- //
- //========================================================================================
-
- class ODMemoryHook
- {
- public:
- // These methods should all be abstract, but MemoryHookList instantiates a
- // ODMemoryHook to use as the head of its linked list, so here we just use empty
- // inlines. A ODMemoryHook still cannot be instantiated because the constructor
- // is protected.
-
- virtual ODBlockSize GetHeaderSize();
-
- virtual ODBlockSize AboutToAllocate(ODBlockSize size) const;
- virtual void* DidAllocate(void* blk, ODBlockSize size);
- virtual const void* AboutToBlockSize(const void* blk);
- virtual void* AboutToFree(void* blk);
- virtual void AboutToRealloc(void*& , ODBlockSize&);
- virtual void* DidRealloc(void* oldBlk, void* newBlk, ODBlockSize);
- virtual void AboutToReset();
- virtual void Comment(const char*);
-
- virtual long GetType( ) const; // Returns type of hook
-
- enum{ kNoType = 0 };
-
- virtual ~ODMemoryHook();
-
- void* operator new(SIZE_T size, MMHeapLocation = kMMTempMemory);
- void operator delete(void* ptr);
-
- protected:
-
- ODMemoryHook();
-
- private:
- ODMemoryHook* fNextHook, * fPreviousHook;
-
- friend MemoryHookList;
-
- ODMemoryHook(const ODMemoryHook& blk);
- ODMemoryHook& operator=(const ODMemoryHook& blk);
- // This class shouldn't be copied.
- };
- #endif
-
-
- #if MM_DEBUG
- //========================================================================================
- // MemoryHookList (MM_DEBUG only)
- //
- // A list of memory hooks. This is a special linked list that assumes the links for
- // the list are fields of ODMemoryHook. This avoids endless recursion were we to
- // allocate nodes for the MemoryHooks here.
- //
- //========================================================================================
-
- class MemoryHookList
- {
- public:
- MemoryHookList();
-
- void Add(ODMemoryHook* aMemoryHook);
- void Remove(ODMemoryHook* aMemoryHook);
- ODMemoryHook* First() const;
- ODMemoryHook* After( ODMemoryHook* ) const;
- ODMemoryHook* Before( ODMemoryHook* ) const;
- ODMemoryHook* Last() const;
-
- ~MemoryHookList();
-
- private:
- ODMemoryHook fHead;
-
- MemoryHookList(const MemoryHookList& blk);
- MemoryHookList& operator=(const MemoryHookList& blk);
- // This class shouldn't be copied.
-
- void* operator new( size_t ) {return 0;} // Will never be allocated from the heap
- void operator delete( void* ) { }
- };
- #endif
-
-
- #endif /*_MEMHOOK_*/
-